# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_special_access.py
# @Time      :2020/12/11 13:46
# @Author    :Zhoujirong
# @Desc      :个人特殊通道
import parameterized
from biz.flow.per_special_access import PerSpecialAccessRequest
from common.log import Log
from biz.cases.base_case import BaseCase
from common.params_operator import Param

class TestPerSpecialAccess(BaseCase):
    data_file_name = 'special_access.yaml'
    @classmethod
    def setUpClass(cls):
        cls.cookie = BaseCase().get_token()
    def test_a_check_user(self):
        '''检查用户'''
        userName = self.file_data.get('userAuthorized')
        ret = PerSpecialAccessRequest.check_user(userName,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertEqual('合法用户',ret.msg)
        self.assertEqual('10000000000000',ret.objectData)

    def test_check_user(self):
        '''检查不存在用户'''
        userName = 'buzhidao'
        ret = PerSpecialAccessRequest.check_user(userName,self.cookie)
        Log.info(ret)
        self.assertEqual('00000001',ret.code)
        self.assertEqual('该用户名不存在',ret.msg)

    def test_b_create(self):
        '''创建特殊通道'''
        userAuthorized = self.file_data.get('userAuthorized')
        deptName = self.file_data.get('deptName')
        orgId = self.file_data.get('orgId')
        beginTimeAuthorized = self.file_data.get('beginTimeAuthorized')
        endTimeAuthorized = self.file_data.get('endTimeAuthorized')
        qryReason = self.file_data.get('qryReason')
        authorizeType = self.file_data.get('authorizeType')
        ret = PerSpecialAccessRequest.create(userAuthorized,
                                            deptName,
                                            orgId,
                                            beginTimeAuthorized,
                                            endTimeAuthorized,
                                            qryReason,
                                            authorizeType,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('操作成功',ret.msg)

    @parameterized.parameterized.expand(Param.from_excel('per_special_access.xls'))
    def test_create_params(self,userAuthorized,
                                deptName,
                                orgId,
                                beginTimeAuthorized,
                                endTimeAuthorized,
                                qryReason,
                                authorizeType,check_code,check_msg,desc):
        self._testMethodDoc = desc
        ret = PerSpecialAccessRequest.create(userAuthorized,
                                deptName,
                                orgId,
                                beginTimeAuthorized,
                                endTimeAuthorized,
                                qryReason,
                                authorizeType,self.cookie)
        Log.info(ret)
        self.assertEqual(check_code,ret.code)
        self.assertIn(check_msg,ret.msg)


    def get_page(self):
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_userAuthorized = self.file_data.get('search_LIKE_userAuthorized')
        search_IN_orgId = self.file_data.get('search_IN_orgId')
        search_GTE_beginTimeAuthorized_DATE = self.file_data.get('search_GTE_beginTimeAuthorized_DATE')
        search_LTE_endTimeAuthorized_DATE = self.file_data.get('search_LTE_endTimeAuthorized_DATE')
        search_LIKE_qryReason = self.file_data.get('search_LIKE_qryReason')
        search_LIKE_operator = self.file_data.get('search_LIKE_operator')
        search_LIKE_authorizeType = self.file_data.get('search_LIKE_authorizeType')
        ret = PerSpecialAccessRequest.get_page(curPage,
                    maxSize,
                    search_LIKE_userAuthorized,
                    search_IN_orgId,
                    search_GTE_beginTimeAuthorized_DATE,
                    search_LTE_endTimeAuthorized_DATE,
                    search_LIKE_qryReason,
                    search_LIKE_operator,
                    search_LIKE_authorizeType,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id

    def test_c_stop(self):
        '''停用特殊通道'''
        id = self.get_page()
        ret = PerSpecialAccessRequest.stop(id,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('操作成功',ret.msg)







if __name__ == "__main__":
    pass